package com.cenwangkeji.resident.presenter.fragment;

import com.cenwangkeji.resident.model.Constant;
import com.cenwangkeji.resident.model.OkHttpUtils;
import com.cenwangkeji.resident.model.bean.BannerBean;
import com.cenwangkeji.resident.model.bean.CommunityNoticeBean;
import com.cenwangkeji.resident.model.bean.HealthContentBean;
import com.cenwangkeji.resident.model.bean.HealthTypeBean;
import com.google.gson.Gson;
import com.lws.basic.persenter.ObserverOnNext;
import com.lws.basic.utils.common.MyLogger;
import com.lws.basic.utils.common.RxUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

/**
 * @松 on 2019/10/23 13:32
 */
public class FilePresenter {
    private I mI;

    public FilePresenter(I i) {
        mI = i;
    }


    public void getBanner(){
        Observable.create(new ObservableOnSubscribe<BannerBean>() {
            @Override
            public void subscribe(ObservableEmitter<BannerBean> emitter) throws Exception {
                Map<Object,Object> map = new HashMap<>();
                map.put("mark",3);
                JSONObject jsonObject = new JSONObject(map);
                String json = OkHttpUtils.post(jsonObject.toString(), Constant.banner);
                MyLogger.i(json);
                Gson gson = new Gson();
                emitter.onNext(gson.fromJson(json, BannerBean.class ));
            }
        }).compose(RxUtils.<BannerBean>io_main())
          .subscribe(new ObserverOnNext<BannerBean>() {
              @Override
              public void onNext(BannerBean bannerbean) {
                  if (mI!=null){
                      mI.onBanner(bannerbean);
                  }

              }
          });
    }


    public interface I{
        void onBanner(BannerBean bannerbean);

    }
}
